<?php
/**
 * Created by JetBrains PhpStorm.
 * User: linhpv
 * Date: 2/18/14
 * Time: 7:46 PM
 * To change this template use File | Settings | File Templates.
 */
 class ValidateLengthMax extends CValidator
{
    public $limit=0;
    public $description_length;
    protected function validateAttribute($object,$attribute){
        $value=$object->$attribute;
        $words = preg_split("/[\s,.]+/", $value);
        $this->description_length=count($words);
        if($this->description_length>$this->limit)
        {
            $this->addError($object,$attribute,$attribute.' must be less than '.$this->limit.' words');
        }

    }
//    public function ClientValidateAttribute($object,$attribute){
//            return "
//                if(".($this->description_length<30).") {
//                    messages.push(".CJSON::encode('your short description is too weak, (short description must over than 30 words)!').");
//                }
//                ";
//    }
}
?>